home *** CD-ROM | disk | FTP | other *** search
/ Czech Logic, Card & Gambling Games / Logické hry.iso / hry / Fish Fillets / script / snowman / code.lua next >
Text File  |  2005-07-16  |  5KB  |  132 lines

  1.  
  2. -- -----------------------------------------------------------------
  3. -- Init
  4. -- -----------------------------------------------------------------
  5. local function prog_init()
  6.     initModels()
  7.     sound_playMusic("music/rybky05.ogg")
  8.     local pokus = getRestartCount()
  9.     local roompole = createArray(3)
  10.  
  11.  
  12.     -- -------------------------------------------------------------
  13.     local function prog_init_room()
  14.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  15.  
  16.         room.rozh = random(50) + 10
  17.         --NOTE: turn off standard black jokes
  18.         stdBlackJoke = function() end
  19.  
  20.         return function()
  21.             if game_getCycles() == room.rozh then
  22.                 room.rozh = room.rozh + 500 + random(1000)
  23.                 if no_dialog() then
  24.                     if random(5) == 1 then
  25.                         addm(2, "tr-m-ztuhl")
  26.                     else
  27.                         addm(3, "tr-m-chlad"..(random(2) + 1))
  28.                         if game_getCycles() < 2000 or random(3) == 1 then
  29.                             addv(5, "tr-v-jid"..(random(2) + 1))
  30.                         end
  31.                     end
  32.                 end
  33.             end
  34.             if isReady(small) and not isReady(big) and not big:isOut() then
  35.                 if snehulak.Y <= 5 then
  36.                     if roompole[1] == 0 or pokus - roompole[1] > random(20) then
  37.                         roompole[1] = pokus
  38.                         addm(11, "tr-m-cvicit")
  39.                     end
  40.                 end
  41.             end
  42.             if isReady(big) and not small:isAlive() then
  43.                 if snehulak.Y >= 5 then
  44.                     if roompole[2] == 0 or pokus - roompole[2] > random(20) then
  45.                         roompole[2] = pokus
  46.                         addv(14, "tr-v-prezil")
  47.                     end
  48.                 end
  49.             end
  50.             if snehulak.uder > 4 and no_dialog() and isReady(big) and isReady(small) then
  51.                 if odd(pokus) then
  52.                     addv(4, "tr-v-agres")
  53.                     snehulak.uder = -10
  54.                 end
  55.             end
  56.         end
  57.     end
  58.  
  59.     -- -------------------------------------------------------------
  60.     local function prog_init_snehulak()
  61.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  62.  
  63.         snehulak.prastil = 0
  64.         snehulak.uder = 0
  65.  
  66.         return function()
  67.             if snehulak.dir == dir_down and ocel.dir ~= dir_down then
  68.                 snehulak.afaze = 2
  69.             else
  70.                 if snehulak.afaze == 2 then
  71.                     snehulak.afaze = 1
  72.                 end
  73.                 pom1 = snehulak.afaze
  74.                 pomb1 = isReady(small) and small.X + 2 == snehulak.X and small.Y - 2 == snehulak.Y and not small:isLeft()
  75.                 if not pomb1 then
  76.                     snehulak.afaze = 0
  77.                     snehulak.prastil = 0
  78.                 elseif snehulak.dir == dir_right then
  79.                     if odd(game_getCycles()) then
  80.                         snehulak.afaze = 1 - snehulak.afaze
  81.                     end
  82.                 else
  83.                     if snehulak.prastil == 0 then
  84.                         snehulak.prastil = -3
  85.                         snehulak.afaze = 1
  86.                     else
  87.                         if snehulak.prastil < -1 then
  88.                             snehulak.prastil = snehulak.prastil + 1
  89.                         end
  90.                         if snehulak.prastil == -1 then
  91.                             snehulak.afaze = 0
  92.                         end
  93.                     end
  94.                 end
  95.                 if pom1 == 0 and snehulak.afaze == 1 then
  96.                     snehulak:talk("tr-x-koste", VOLUME_FULL)
  97.                     if no_dialog() then
  98.                         addm(2, "tr-m-au"..(random(2) + 1))
  99.                     end
  100.                     snehulak.uder = snehulak.uder + 1
  101.                 end
  102.             end
  103.             snehulak:updateAnim()
  104.         end
  105.     end
  106.  
  107.     -- --------------------
  108.     local update_table = {}
  109.     local subinit
  110.     subinit = prog_init_room()
  111.     if subinit then
  112.         table.insert(update_table, subinit)
  113.     end
  114.     subinit = prog_init_snehulak()
  115.     if subinit then
  116.         table.insert(update_table, subinit)
  117.     end
  118.     return update_table
  119. end
  120. local update_table = prog_init()
  121.  
  122.  
  123. -- -----------------------------------------------------------------
  124. -- Update
  125. -- -----------------------------------------------------------------
  126. function prog_update()
  127.     for key, subupdate in pairs(update_table) do
  128.         subupdate()
  129.     end
  130. end
  131.  
  132.